<template>
	<el-tabs style="margin-top: 20px;" v-model="activeName" type="card" @tab-click="handleClick">
		<el-tab-pane label="Banner" name="first">
			<!--Banner  -->
			<el-row style="margin-top: 5px;padding: 5px 0;font-size: 15px;">
				<el-col :span="24">
					<el-button type="primary" @click="edit('addSY')">+新增
					</el-button>
				</el-col>
			</el-row>

			<el-table :data="pageInfo.vos" v-loading="table_loading" element-table_loading-text="加载中" stripe @sort-change='order'
			 style="width: 100%">
				<el-table-column width="150" label="图片">
					<template scope="scope">
						<img class="banner" :src="scope.row.bannerIcon">
					</template>
				</el-table-column>
				<el-table-column prop="bannerName" label="名称">
				</el-table-column>
				<el-table-column label="排序值" prop="banner_Sort" width="115" sortable='custom'>
					<template scope="scope">
						<el-input v-model="scope.row.bannerSort" style="width: 80px;" @blur="editOrder(scope.row,$event)" @focus="setOldProbability(scope.row)"></el-input>
					</template>
				</el-table-column>
				<el-table-column label="跳转类型">
					<template scope="scope">
						<span>{{ findState(scope.row.bannerType,bannerType) }}</span>
					</template>
				</el-table-column>
				<el-table-column sortable='custom' prop="CRE_TIME" label="创建时间">
					<template scope="scope">
						<span>{{dateFormat(scope.row.creTime,'y-m-d h:i')}}</span>
					</template>
				</el-table-column>
				<el-table-column label="操作" width="250">
					<template scope="scope">
						<el-button size="small" type="primary" @click="edit(scope.row.bannerCode)">编辑
						</el-button>
						<el-button size="small" type="danger" @click="handleDetele(scope.row.bannerCode)">删除
						</el-button>
						<el-button size="small" :type="scope.row.bannerState=='Y'?'danger':'success'" @click="using(scope.row)">{{scope.row.bannerState=='Y'?'禁用':'启用'}}
						</el-button>
					</template>
				</el-table-column>
			</el-table>
		</el-tab-pane>

		<el-tab-pane label="运营位" name="second">
			<!-- 运营位 -->
			<el-table :data="position_Info.dtos" v-loading="table_loading" element-table_loading-text="加载中" stripe @sort-change='order'
			 style="width: 100%">
				<el-table-column width="250" prop="operationName" label="名称">
				</el-table-column>
				<el-table-column label="图片">
					<template scope="scope">
						<img v-for="item in scope.row.icons" style="width: 80px;margin: 5px;" class="banner" :src="item">
					</template>
				</el-table-column>
				<el-table-column label="跳转类型">
					<template scope="scope">
						<span>{{scope.row.operationImage }}</span>
					</template>
				</el-table-column>
				<!-- 运营位 -->
				<el-table-column label="操作" width="250">
					<template scope="scope">
						<el-button size="small" type="primary" @click="edit2(scope.row.operationCode)">编辑
						</el-button>

					</template>
				</el-table-column>
			</el-table>

		</el-tab-pane>
		<el-tab-pane label="推荐" name="third">
			<div class="customer">
				<el-form :model="form" style="background-color: #FFFFFF;">
					<el-form-item label="选择商品：" label-width="120px">
						<el-button size="small" type="primary" @click="fetchGoods(1);dialogTableVisible=true">点击选择
						</el-button>
					</el-form-item>
					<el-form-item label="选择酒店：" label-width="120px">
						<el-button size="small" type="primary" @click="fetchHotel(1);dialogTableVisible3=true">点击选择
						</el-button>
					</el-form-item>
					<el-form-item label="选择消费服务：" label-width="120px">
						<el-button size="small" type="primary" @click="fetchVoucher(1);dialogTableVisible4=true">点击选择
						</el-button>
					</el-form-item>
					<!-- 	<el-button size="medium" style="width: 150px;margin-bottom: 10px;"   type="primary" @click="fetchGoods(1);dialogTableVisible=true">增加
            			</el-button> -->

				</el-form>
				<el-table :data="pageInfo2.rows" style="margin-bottom: 20px;width:100%">
					<el-table-column label="排序值" width="110">
						<template scope="scope">
							<el-button @click="setOldProbability(scope.row,scope.row.sort_value);showDilog(scope.row)">{{ scope.row.sort_value }}</el-button>
						</template>
					</el-table-column>
					<el-table-column  width="300" label="商品名称">
						<template scope="scope">
							<div style="display: inline-block;">
								<img class="banner" :src="scope.row.goodCover" style="width:120px;">
							</div>
							<div style="display: inline-block;width: 120px;vertical-align: middle;padding: 10px;">{{scope.row.goodName}}</div>
						</template>
					</el-table-column>
					<el-table-column  min-width="150" prop="good_Price" label="价格（元）">
						<template scope="scope">
							<span>{{ scope.row.goodPrice }}</span>
						</template>
					</el-table-column>
					<el-table-column  min-width="150" label="操作">
						<template scope="scope">
							<el-button @click.native.prevent="deleteRow(scope.$index,scope.row.goodId)" type="danger" size="small">
								删除
							</el-button>
						</template>
					</el-table-column>
				</el-table>
				<div class="paginate">
					<el-pagination @current-change="handleCurrentChange2" :current-page="pageInfo2.pageNum" :page-size="pageInfo2.pageSize"
					 layout="total, prev, pager, next, jumper" :total="pageInfo2.count">
					</el-pagination>
				</div>
				</el-row>
				<div style="margin-left: 30px;margin-bottom: 20px;">
					<el-button type="primary" @click="submit()" :loading="loading">保 存 商 品
					</el-button>
				</div>
				<!--选择商品-->
				<el-dialog title="选择商品" v-model="dialogTableVisible" size="large">
					<el-row>
						<el-col :span="24">
							<el-form :inline="true" class="demo-form-inline" label-width="80px">
								<el-form-item label="商品名称">
									<el-col :span="18">
										<el-input v-model="formInline.goodName"></el-input>
									</el-col>
								</el-form-item>
								<el-button type="primary" @click="fetchGoods(1)">查询</el-button>
							</el-form>
						</el-col>
					</el-row>
					<el-table :data="gridData">
						<el-table-column width="215" label="商品">
							<template scope="scope">
								<div style="display: inline-block;">
									<img class="banner" :src="scope.row.goodCover" style="width:55px;">
								</div>
								<div style="display: inline-block;width: 120px;vertical-align: middle;padding: 10px;">{{scope.row.goodName}}</div>
							</template>
						</el-table-column>
						<el-table-column prop="DIS_PRICE" label="分类">
							<template scope="scope">
								<span>{{ scope.row.goodOneCateName }} - {{ scope.row.goodTwoCateName }}</span>
							</template>
						</el-table-column>
						<el-table-column prop="good_Price" sortable='custom' label="起售价（元）">
							<template scope="scope">
								<span>{{ scope.row.goodPrice }}</span>
							</template>
						</el-table-column>
						<el-table-column prop="T1.good_Discount_Price" label="优惠价（元）">
							<template scope="scope">
								<span v-if="scope.row.goodIsDiscount==1">{{ scope.row.goodDiscountPrice }}</span>
								<span v-else>未启用</span>
							</template>
						</el-table-column>
						<el-table-column prop="good_Ratio" label="补贴比例">
							<template scope="scope">
								<span>{{ scope.row.goodRatio*100 }}%</span>
							</template>
						</el-table-column>
						<el-table-column prop="sales" label="销量">
						</el-table-column>
						<el-table-column prop="stock" label="库存">
						</el-table-column>
						<el-table-column prop="cre_Time" label="上架时间">
							<template scope="scope">
								<span>{{scope.row.creTime}}</span>
							</template>
						</el-table-column>
						<el-table-column label="选择" width="150">
							<template scope="scope">
								<el-checkbox-group v-model="checked" :max="100" @change="handleCheckedCitiesChange">
									<el-checkbox :label="scope.row">选择</el-checkbox>
								</el-checkbox-group>
							</template>
						</el-table-column>
					</el-table>
					<div class="paginate" style="float: left;">
						<el-pagination @current-change="handleCurrentChange_list" :current-page="pageInfo.pageNum" :page-size="pageInfo.pageSize"
						 layout="total, prev, pager, next, jumper" :total="pageInfo.count">
						</el-pagination>
					</div>
					<div style="float: right;margin-top:19px;margin-right: 20px;">
						<el-checkbox v-model="checkAll" @change="handleCheckAllChange" style="margin-right: 40px;" :indeterminate="isIndeterminate">全选</el-checkbox>
						<el-button type="primary" @click="onSubmit()">确定</el-button>
					</div>
				</el-dialog>
				<!--选择酒店-->
				<el-dialog title="选择酒店" v-model="dialogTableVisible3" size="large">
					<el-table :data="gridData">
						<el-table-column label="图片">
							<template scope="scope">
								<img class="banner" :src="scope.row.roomImg" style="width: 120px">
							</template>
						</el-table-column>
						<el-table-column prop="roomName" label="酒店名称">
						</el-table-column>
						<el-table-column prop="sttPrice" label="周日-周四价格">
						</el-table-column>
						<el-table-column prop="ftsPrice" label="周五-周六价格">
						</el-table-column>
						<el-table-column prop="hotel_Room_Ratio" label="补贴比例">
							<template scope="scope">
								<span>{{ scope.row.roomDefRatio*100 }}%</span>
							</template>
						</el-table-column>
						<el-table-column label="选择" width="150">
							<template scope="scope">
								<el-checkbox-group v-model="checked" :max="100" @change="handleCheckedCitiesChange">
									<el-checkbox :label="scope.row">选择</el-checkbox>
								</el-checkbox-group>
							</template>
						</el-table-column>
					</el-table>
					<div class="paginate" style="float: left;">
						<el-pagination @current-change="handleCurrentChange" :current-page="pageInfo.pageNum" :page-size="pageInfo.pageSize"
						 layout="total, prev, pager, next, jumper" :total="pageInfo.count">
						</el-pagination>
					</div>
					<div style="float: right;margin-top:19px;margin-right: 20px;">
						<el-checkbox v-model="checkAll" @change="handleCheckAllChange" style="margin-right: 40px;" :indeterminate="isIndeterminate">全选</el-checkbox>
						<el-button type="primary" @click="onSubmit(2)">确定</el-button>
					</div>
				</el-dialog>
				<!--选择消费服务-->
				<el-dialog title="选择消费服务" v-model="dialogTableVisible4" size="large">
					<el-table :data="gridData">
						<el-table-column label="封面">
							<template scope="scope">
								<img class="banner" :src="scope.row.voucherCover" style="width: 120px">
							</template>
						</el-table-column>
						<el-table-column prop="voucherName" label="消费服务名称">
						</el-table-column>
						<el-table-column prop="voucherAmt" label="价格">
						</el-table-column>
						<el-table-column prop="voucherSunNum" label="销量">
						</el-table-column>
						<el-table-column prop="voucherNum" label="库存">
						</el-table-column>
						<el-table-column label="有效期">
							<template scope="scope">
								<span>{{ scope.row.voucherStartTime }}至{{ scope.row.voucherEndTime }}</span>
							</template>
						</el-table-column>
						<el-table-column label="选择" width="150">
							<template scope="scope">
								<el-checkbox-group v-model="checked" :max="100" @change="handleCheckedCitiesChange">
									<el-checkbox :label="scope.row">选择</el-checkbox>
								</el-checkbox-group>
							</template>
						</el-table-column>
					</el-table>
					<div class="paginate" style="float: left;">
						<el-pagination @current-change="handleCurrentChange" :current-page="pageInfo.pageNum" :page-size="pageInfo.pageSize"
						 layout="total, prev, pager, next, jumper" :total="pageInfo.count">
						</el-pagination>
					</div>
					<div style="float: right;margin-top:19px;margin-right: 20px;">
						<el-checkbox v-model="checkAll" @change="handleCheckAllChange" style="margin-right: 40px;" :indeterminate="isIndeterminate">全选</el-checkbox>
						<el-button type="primary" @click="onSubmit(3)">确定</el-button>
					</div>
				</el-dialog>

				<!--排序值-->
				<el-dialog title="排序值" v-model="dialogTableVisible2" size="tiny">
					<div style="text-align: center;">
						<el-input v-model="f.sort_value" style="width:150px;"></el-input>
						<div style="margin-top:19px;margin-right: 20px;margin-bottom: 20px;">
							<el-button type="primary" @click="editOrder_list(f,f.sort_value)">确定</el-button>
						</div>
					</div>
				</el-dialog>
			</div>

		</el-tab-pane>

	</el-tabs>

</template>
<style>

</style>
<script>
	export default {
		data() {
			return {
				dialogTableVisible: false,
				dialogTableVisible2: false,
				dialogTableVisible3: false,
				dialogTableVisible4: false,
				position_Info: [],
				activeName: 'first',
				pageInfo: {
					pageNum: 1,
					pageSize: 10,
					count: 1,
					vos: []
				},
				table_loading: false,
				bannerType: [{
					text: '单商品',
					value: 'D'
				}, {
					text: '多商品',
					value: 'DD'
				}, {
					text: '链接',
					value: 'L'
				}, {
					text: '商家',
					value: 'DP'
				}, {
					text: '文章',
					value: 'T'
				}, {
					text: '不跳转',
					value: 'B'
				},
				{
					text: '商家入驻',
					value: 'S'
				},
				],
				desc: 'DESC',
				sorts: 'BANNER_SORT + 0',
				// 
				formInline: {
					goodName: '',
					goodOneCate: '',
					goodTwoCate: '',
					goodState: 2,
					storeId: '',
					pageNum: 1,
					pageSize: 5,
					sort: 'T1.CRE_TIME',
					desc: 'DESC',
					goodIsDiscount: ''
				},
				pageInfo3: {
					pageNum: 1,
					pageSize: 1,
					count: 1,
					rows: []
				},
				pageInfo2: {
					pageNum: 1,
					pageSize: 5,
					count: 1,
					rows: []
				},
				dialogVisible: false,
				table_loading: false,
				form: {
					goodsCodeList: [],
					operationCode: 5
				},
				storeGoodDtos: [],
				gridData: [],
				checked: [],
				checkAll: false,
				isIndeterminate: true,
				arr: [],
				URL: URL,
				loading: false,
				sortList: [],
				secondList: [],
				thirdList: [],
				f: {},
				flag2: false
			}
		},
		created() {

		},
		activated() {
			this.fetchData(this.pageInfo.pageNum);
			this.fetchData_list()
			this.position_list();
		},
		methods: {
			handleClick(tab, event) {
				console.log(tab, event);
			},
			// fetchData_listof() {
			//   this.dataApi.ajax('operationSelect', { operationCode: 5 }, res => {
			//     if (res.responseType === 'S') {
			//       this.pageInfo2 = {
			//         pageNum: 1,
			//         pageSize: 5,
			//         count: 1,
			//         rows: []
			//       }
			//       for (var i = res.dtos.length - 1; i >= 0; i--) {
			//         res.dtos[i].sort_value = i + 1
			//         res.dtos[i].index = i
			//         res.dtos[i].OldProbability = i + 1
			//       }
			//       let arr = generateArr(res.dtos)
			//       this.storeGoodDtos = res.dtos
			//       this.pageInfo2.count = res.dtos.length
			//       this.pageInfo2.rows = arr.splice(0, 5)
			//     }
			//   });
			// },
			fetchData(page = 1) {
				// 首页banner
				this.table_loading = true;
				this.pageInfo.pageNum = page
				this.dataApi.ajax('bannerPage', {
					pageNum: this.pageInfo.pageNum,
					pageSize: 10,
					sort: this.sorts,
					desc: this.desc,
					bannerPosition: 'SY'
				}, res => {
					// console.log(res, '测试删除-更新数据')
					this.table_loading = false;
					if (res.responseType === 'S') {
						this.pageInfo = res

					}
				});

			},
			position_list() {

				this.dataApi.ajax('operationList', {}, res => {
					//console.log(res)
					this.table_loading = false;
					if (res.responseType === 'S') {
						var position_Info = res
						var arr = position_Info.dtos

						this.position_Info = position_Info
	

					}
				});

			},
			edit(id) {
			
				this.$router.push('/official/banner_list_detail/' + id)
			},
			edit2(data) {
				this.$router.push('/official/new_index_detail/' + data)
			},
			using(item) {
				var type = ''
				var state = ''
				let data = generateObj(item)
				if (data.bannerState == 'Y') {
					type = '禁用'
					state = 'J'
				} else {
					type = '启用'
					state = 'Y'
				}
				data.bannerState = state
				this.$confirm('确定' + type + '?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					this.dataApi.ajax('bannerEdit', data, res => {
						if (res.responseType === 'S') {
							this.showMsg(type + '成功')
							this.fetchData(this.pageInfo.pageNum)
						}
					});
				}).catch(() => {

				});
			},
			handleCurrentChange(val) {
				if(this.dialogTableVisible3 == true){
					this.fetchHotel(val)
				}
				if(this.dialogTableVisible4 == true){
					this.fetchData(val)
				}
			},
			handleDetele(id) {
				this.$confirm('确定删除?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					this.dataApi.ajax('bannerDelete', {
						bannerCode: id
					}, res => {
						if (res.responseType === 'S') {
							this.showMsg('删除成功');
							this.fetchData(this.pageInfo.pageNum);
						}
					});
				}).catch(() => {

				});

			},
			order(column) {
				if (!column.order) {
					return;
				}
				if (column.order == 'ascending') {
					this.desc = 'ASC'
				} else {
					this.desc = 'DESC'
				}
				this.sorts = column.prop
				this.fetchData(this.pageInfo.pageNum)
			},


			// -------------------------------添加商品---------------------------------------------------------
			fetchData_list() {
				this.dataApi.ajax('operationSelect', {
					operationCode: this.form.operationCode
				}, res => {
						// console.log(this.form.operationCode,'Code')
						console.log(465)
					if (res.responseType === 'S') {
						this.pageInfo2 = {
							pageNum: 1,
							pageSize: 5,
							count: 1,
							rows: []
						}
						for (var i = res.dtos.length - 1; i >= 0; i--) {
							res.dtos[i].sort_value = i + 1
							res.dtos[i].index = i
							res.dtos[i].OldProbability = i + 1
						}
						let arr = generateArr(res.dtos)
						this.storeGoodDtos = res.dtos
						this.pageInfo2.count = res.dtos.length
						this.pageInfo2.rows = arr.splice(0, 5)
					}
				});
			},
			// 123
			fetchGoods(page = 1) {
				this.checked = []
				this.pageInfo.pageNum = page;
				this.formInline.pageNum = page;
				this.dataApi.ajax('selectPageStoreGood', this.formInline, res => {
					if (res.responseType === 'S') {
						this.pageInfo = res
						this.gridData = res.dtos
						this.arr = []
						this.checked = []
						this.inisIndeterminate = true
						for (var i = this.gridData.length - 1; i >= 0; i--) {
							this.arr.push(this.gridData[i])
						}

						if (this.checked.length == this.arr.length) {
							this.checkAll = true
						} else {
							this.checkAll = false;
						}

					}
				});

			},
			fetchHotel(page = 1) {
				this.checked = []
				this.pageInfo.pageNum = page;
				this.dataApi.ajax('selectPageStoreHotelRoom', {
					pageNum: this.pageInfo.pageNum,
					pageSize: 5,
					sort: 'CRE_TIME',
					desc: 'DESC',
					roomState: 1
				}, res => {
					if (res.responseType === 'S') {
						this.pageInfo = res
						this.gridData = res.dtos
						this.arr = []
						this.checked = []
						this.inisIndeterminate = true
						for (var i = this.gridData.length - 1; i >= 0; i--) {
							this.arr.push(this.gridData[i])
						}
						if (this.checked.length == this.arr.length) {
							this.checkAll = true
						} else {
							this.checkAll = false;
						}

					}
				});

			},
			fetchVoucher(page = 1) {
				this.checked = []
				this.pageInfo.pageNum = page;
				this.dataApi.ajax('selectPagePayStoreVoucher', {
					pageNum: this.pageInfo.pageNum,
					pageSize: 5,
					sort: 'VOUCHER_AMT',
					desc: 'DESC',
					voucherStat: 1,
					voucherType:'2'
				}, res => {
					if (res.responseType === 'S') {
						this.pageInfo = res
						this.gridData = res.dtos
						this.arr = []
						this.checked = []
						this.inisIndeterminate = true
						for (var i = this.gridData.length - 1; i >= 0; i--) {
							this.arr.push(this.gridData[i])
						}
						if (this.checked.length == this.arr.length) {
							this.checkAll = true
						} else {
							this.checkAll = false;
						}

					}
				});
			},
			// 2

			fetchList() {
				this.dataApi.ajax('MallGoodClassifyControl/selectOneList', null, res => {
					if (res.responseType === 0) {
						this.sortList = res.goodsClassifyPojos
					}
				});
			},
			selectSort() {
				this.formInline.secondCode = ''
				this.formInline.thcondCode = ''
				this.dataApi.ajax('MallGoodClassifyControl/selectListOne', {
					classifyName: this.formInline.classifyCode
				}, res => {
					if (res.responseType === 0) {
						this.secondList = res.goodsClassifyPojos
					}
				});
			},
			selectSort2() {
				if (this.flag2 === true) this.formInline.thcondCode = ''
				this.flag2 = true;
				this.dataApi.ajax('MallGoodClassifyControl/selectListOne', {
					classifyName: this.formInline.secondCode
				}, res => {
					//console.log(res)
					if (res.responseType === 0) {
						this.thirdList = res.goodsClassifyPojos
					}
				});
			},
		 

				onSubmit(type) {
 
						// this.pageInfo2.rows=this.checked
						for (var key in this.storeGoodDtos) {
							for (var i in this.checked) {
								if (type == 1) {
									if (this.storeGoodDtos[key].goodId.indexOf(this.checked[i].goodId) !== -1) {
										this.checked.splice([i], 1)
									}
								} else if (type == 2) {
									if (this.storeGoodDtos[key].goodId.indexOf(this.checked[i].roomId) !== -1) {
										this.checked.splice([i], 1)
									}
								} else if (type == 3) {
									if (this.storeGoodDtos[key].goodId.indexOf(this.checked[i].voucherId) !== -1) {
										this.checked.splice([i], 1)
									}
								}

							}
						}
						if (this.checked.length <= 0) {
							return false;
						}
						this.storeGoodDtos = this.storeGoodDtos.concat(this.checked);
						// -----------------------------------
                        console.log(this.storeGoodDtos,'this.storeGoodDtos')
						for (var i = this.storeGoodDtos.length - 1; i >= 0; i--) {
							this.storeGoodDtos[i].sort_value = i + 1;
							this.storeGoodDtos[i].index = i;
							this.storeGoodDtos[i].OldProbability = i + 1;

							if (!this.storeGoodDtos[i].goodId && type == 2) {
								this.storeGoodDtos[i]['goodId'] = this.storeGoodDtos[i].roomId
								this.storeGoodDtos[i]['goodName'] = this.storeGoodDtos[i].roomName
								this.storeGoodDtos[i]['goodCover'] = this.storeGoodDtos[i].roomImg
								this.storeGoodDtos[i]['goodPrice'] = this.storeGoodDtos[i].sttPrice
								this.storeGoodDtos[i]['goodType'] = type;


							}
							if (!this.storeGoodDtos[i].goodId && type == 3) {
								this.storeGoodDtos[i]['goodId'] = this.storeGoodDtos[i].voucherId;
								this.storeGoodDtos[i]['goodName'] = this.storeGoodDtos[i].voucherName;
								this.storeGoodDtos[i]['goodCover'] = this.storeGoodDtos[i].voucherCover;
								this.storeGoodDtos[i]['goodPrice'] = this.storeGoodDtos[i].voucherAmt;
								this.storeGoodDtos[i]['goodType'] = type;
							}





						}
						var arr = generateArr(this.storeGoodDtos)
						this.pageInfo2.count = this.storeGoodDtos.length
					 
						this.pageInfo2.rows = arr.splice(0, 5)
						this.dialogTableVisible = false;
						this.dialogTableVisible3 = false;
						this.dialogTableVisible4 = false;

					},
					// 1
					submit() {
						if(this.form.goodsCodeList.length<1){
							this.form.goodsCodeList=''
						}
						let obj = generateObj(this.form)
						
						if (this.storeGoodDtos.length == 0) {
						  this.$message({
						    type: 'warning',
						    message: '请选择至少一个商品!'
						  });
						  return;
						}
						
						var arr = []
						for (var i = 0; i < this.storeGoodDtos.length; i++) {
						  arr.push({
						    goodId:this.storeGoodDtos[i].goodId,
						    goodType: this.storeGoodDtos[i].goodType?this.storeGoodDtos[i].goodType.toString():1
						  })
						}
						obj.dtos  = arr
						// console.log(obj,'首页obj')
						this.loading = true
						this.dataApi.ajax('operationEdit', obj, res => {
						  if (res.responseType === 'S') {
						    this.showMsg('保存成功')
						    this.loading = false;
						    this.fetchData_list();
						  }
						});

					},
					handleCurrentChange_list(val) {
						this.fetchGoods(val)
						this.checkAll = false
					},
					handleCurrentChange2(val) {
						this.pageInfo2.pageNum = val
						// console.log(arr.splice(5*(val-1),(5*(val-1)+5)))
						var arr2 = []
						var arr = generateArr(this.storeGoodDtos)
						arr2 = arr.slice(5 * (val - 1), (5 * (val - 1) + 5))
						this.pageInfo2.rows = arr2
					},
					handleCheckAllChange(event) {

						if (event.target.checked == false) {
							for (var i = this.arr.length - 1; i >= 0; i--) {
								for (var j = this.checked.length - 1; j >= 0; j--) {
									if (this.arr.indexOf(this.checked[j]) !== -1) {
										this.checked.splice(j, 1)
									}
								}
							}

						} else {
							this.isIndeterminate = false;
							for (var i = this.gridData.length - 1; i >= 0; i--) {
								if (this.checked.indexOf(this.arr[i]) === -1) {
									this.checked.push(this.arr[i])
								}
							}
						}


					},
					handleCheckedCitiesChange(value) {

						let arr = []
						for (var i = this.arr.length - 1; i >= 0; i--) {
							for (var j = this.checked.length - 1; j >= 0; j--) {
								if (arr.indexOf(this.checked[j]) === -1 && this.arr[i] === this.checked[j]) {
									arr.push(this.checked[j])
								}
							}
						}


						let checkedCount = arr.length;
						this.checkAll = checkedCount === this.arr.length;
						this.isIndeterminate = checkedCount > 0 && checkedCount < this.arr.length;
					},
					deleteRow(index, id) {
						this.pageInfo2.rows.splice(index, 1);
						// this.storeGoodDtos.splice(index, 1);
						for (var i = this.storeGoodDtos.length - 1; i >= 0; i--) {
							if (this.storeGoodDtos[i].goodId.indexOf(id) !== -1) {
								this.storeGoodDtos.splice([i], 1)
							}
						}
						for (var i = this.storeGoodDtos.length - 1; i >= 0; i--) {
							this.storeGoodDtos[i].sort_value = i + 1
							this.storeGoodDtos[i].index = i
							this.storeGoodDtos[i].OldProbability = i + 1
						}
						this.handleCurrentChange2(this.pageInfo2.pageNum)
						this.pageInfo2.count = this.storeGoodDtos.length
					},
					editOrder_list(item, e) {
						// console.log(item.index)

						// var arr_old=generateArr(this.storeGoodDtos)
						// this.storeGoodDtos=[]
						// this.storeGoodDtos=arr_old 
						// this.pageInfo2.rows=[]
						var val = e //输入的排序值
						if (!isFloat(e)) {
							this.showMsg('输入的排序值不正确', 'warning')
							return
						}
						// console.log(e.target.value,item.OldProbability)
						// return;
						if (Math.floor(val) <= 0) {
							val = item.OldProbability || 0;
							return false;
						}
						if (item.OldProbability == val) return false;
						if (val > this.storeGoodDtos.length) {
							this.showMsg('排序值不能大于总数', 'warning')
							item.sort_value = item.OldProbability
							return false;
						}
						//let currentList = this.pageInfo2.rows;

						let newVal = this.storeGoodDtos[item.index] //获取当前的元素值


						let oldVal = this.storeGoodDtos[val - 1] //获取要替换的元素值



						this.storeGoodDtos.splice(val - 1, 1, newVal) //替换旧值并新增的新值
						this.storeGoodDtos.splice(item.index, 1, oldVal) //替换新值并新增的旧值
						// console.log(this.storeGoodDtos,item.OldProbability-1,index-1)
						// console.log(item.OldProbability,val)//旧的排序值

						oldVal.index = item.index
						newVal.index = parseInt(val - 1)

						// oldVal.sort_value = oldVal.index+1+""
						// newVal.sort_value = newVal.index+1+""

						for (var i = this.storeGoodDtos.length - 1; i >= 0; i--) {

							// this.$set(this.storeGoodDtos[i],'sort_value',this.storeGoodDtos[i].index+1+"")
							this.storeGoodDtos[i].sort_value = this.storeGoodDtos[i].index + 1 + ""

							//console.log(this.storeGoodDtos[i].sort_value);
						}

						this.handleCurrentChange2(this.pageInfo2.pageNum) //根据所有数据数组切割成当前页数组
						this.dialogTableVisible2 = false
					},
					setOldProbability(item, index) {
						item.OldProbability = index
					},
					fanhui() {
						history.back(-1)
					},
					uploading(f) {
						this.dataApi.upload('file/upload', f.file, res => {
							//console.log(res)
							if (res.responseType === 0) {
								f.images.splice(f.index, 1, this.URL + res.fileName)
							}
						});
					},
					showDilog(item) {
						this.dialogTableVisible2 = true
						this.f = item
					},
					// ----------------------------------------------------------------------------------------------

			}
		}
</script>
